import { Behaviour, HitTestScript, TextRenderer } from "./gameengine";
import { user } from "./user";


export class Shop extends Behaviour {


    


    protected onStart() {
        const textRender1 = this.displayObject.children[0].getScript(TextRenderer);
        textRender1.text = "             ";
        const textRender2 = this.displayObject.children[1].getScript(TextRenderer);
        textRender2.text = "             ";
 		        const textRender3 = this.displayObject.children[2].getScript(TextRenderer);
 		        textRender3.text = "             ";
 		        const textRender4 = this.displayObject.children[3].getScript(TextRenderer);
 		        textRender4.text = "             ";
 		        const textRender5 = this.displayObject.children[4].getScript(TextRenderer);
 		        textRender5.text = "             ";
 		        const textRender6 = this.displayObject.children[5].getScript(TextRenderer);
 		        textRender6.text = "             ";
 		        const textRender7 = this.displayObject.children[6].getScript(TextRenderer);
 		        textRender7.text = "             ";

        textRender2.displayObject.getScript(HitTestScript).onClick = () => {
            console.log("2");
            if(user.gold>=200){
                user.gold -= 200;    
                user.hp += 200;
                }
            }
            
    
            textRender3.displayObject.getScript(HitTestScript).onClick = () => {
                console.log("2");
                if(user.gold>=200){
                user.gold -= 200;    
                user.def += 5;
                }
        }

        textRender4.displayObject.getScript(HitTestScript).onClick = () => {
            console.log("2");
            if(user.gold>=200){
            user.gold -= 200;    
            user.att += 5;
            }
        }

        textRender5.displayObject.getScript(HitTestScript).onClick = () => {
            console.log("2");
            if(user.gold>=200){
            user.gold -= 200;    
            user.peach += 1;
            }
        }

        textRender6.displayObject.getScript(HitTestScript).onClick = () => {
            console.log("2");
            if(user.gold>=200){
            user.gold -= 200;    
            user.apple += 1;
            }
        }

        textRender7.displayObject.getScript(HitTestScript).onClick = () => {
            console.log("2");
            if(user.gold>=200){
            user.gold -= 200;    
            user.banana += 1;
            }
        }

        textRender1.displayObject.getScript(HitTestScript).onClick = () => {
            console.log("1");
            const gameObjct = this.displayObject;
            this.displayObject.parent.removeChild(this.displayObject)
            gameObjct.parent = null;
             //this.displayObject = null;
             
        }

    }
    protected onUpdate(advancedTime: number) {

        

    }
}

